package com.ycfmedical.bed.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;

import com.tencent.TIMConversationType;
import com.ycfmedical.bed.ApiConfigs;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.bean.ImUser;
import com.ycfmedical.bed.local.DataManager;
import com.ycfmedical.bed.ui.ChatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.mvp.XLazyFragment;

/**
 * Created by Administrator on 2017-04-05.
 */

public class CallNurseFragment extends XLazyFragment
{
    @BindView(R.id.tab_coffee)
    TableLayout tabCoffee;
    @BindView(R.id.tab_food)
    TableLayout tabFood;
    @BindView(R.id.tab_infusions)
    TableLayout tabInfusions;
    @BindView(R.id.tab_nurse)
    TableLayout tabNurse;
    @BindView(R.id.tab_wc)
    TableLayout tabWc;
    @BindView(R.id.tab_other)
    TableLayout tabOther;
    @BindView(R.id.view_mask)
    View viewMask;
    
    
    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_callhelp;
    }
    
    @Override
    public Object newP()
    {
        return null;
    }
    
    @Override
    public void initData(Bundle savedInstanceState)
    {
        _CheckImUse();
    }

    @Override
    protected void onResumeLazy() {
        super.onResumeLazy();
        _CheckImUse();
    }

    // 检查Im功能是否可用
    private void _CheckImUse()
    {
        if (!Kits.Empty.check(ImUser.getInstance().getImAccount()))
        {
            _setTabClickAble(true);
            _showMask(false);
        }
        else
        {
            _setTabClickAble(false);
            _showMask(true);
            getvDelegate().toastShort("当前IM账号异常，通讯功能关闭");
        }
    }
    
    private void _showMask(boolean isShow){

        if(isShow == true) {
            viewMask.setVisibility(View.VISIBLE);
        } else {
            viewMask.setVisibility(View.GONE);
        }
    }
        
    // 设置按钮是否可以被点击
    private void _setTabClickAble(boolean onClickable)
    {
        tabCoffee.setEnabled(onClickable);
        tabFood.setEnabled(onClickable);
        tabInfusions.setEnabled(onClickable);
        tabNurse.setEnabled(onClickable);
        tabWc.setEnabled(onClickable);
        tabOther.setEnabled(onClickable);
    }
    
    // 点击事件
    @OnClick({R.id.tab_coffee, R.id.tab_food, R.id.tab_infusions, R.id.tab_nurse, R.id.tab_wc, R.id.tab_other})
    public void onViewClicked(View view)
    {
        // 如果床头APP登录账号为 护士 则直接返回
        if (ImUser.getInstance().getImAccount().equals(ApiConfigs.USER_NURSE))
        {
            getvDelegate().toastShort("请切换账号，当前账号为nurse");
            return;
        }
        
        String msg = "";
        String bedId = DataManager.getInstance().getUser().getBedId();
        String username = DataManager.getInstance().getUser().getName();
        
        switch (view.getId())
        {
            case R.id.tab_coffee:
                msg = bedId + "号床 " + username + " 需要咖啡";
                break;
            case R.id.tab_food:
                msg = bedId + "号床 " + username + " 需要点餐";
                break;
            case R.id.tab_infusions:
                msg = bedId + "号床 " + username + " 需要准备配液";
                break;
            case R.id.tab_nurse:
                msg = bedId + "号床 " + username + " 需要护理帮助";
                break;
            case R.id.tab_wc:
                msg = bedId + "号床 " + username + " 需要入厕帮助";
                break;
            case R.id.tab_other:
                msg = bedId + "号床 " + username + " 需要其他帮助";
                break;
        }
        // 跳转到聊天界面
        ChatActivity.navToNurseChat(context, msg);
    }
    
}
